﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Tasks.Common.Entitys;
using System.Collections;
using Tasks.Core;
using System.IO;
using Tasks.UI.Models.SceneryModels;
using Tasks.Common.Enum;
using Tasks.Common;
using Tasks.Business;
using Tasks.UI.Models.TourGuide;
using Tasks.UI.Models.Shop;
using Tasks.UI.Models;
using Tasks.UI.Models.SystemSetting;
using Tasks.UI.Models.PrintHead;
using Tasks.UI.Models.Article;
using Tasks.API;
namespace Tasks.UI.Controllers
{
    /// <summary>
    /// 系统设置控制器
    /// </summary>
    public class SystemSettingController : BaseController
    {
        BasedataBLL baseBll = BusinessFactory.BasedataBLL;

        /// <summary>
        /// 功能大全主页
        /// </summary>
        /// <returns></returns>
        public ActionResult FunctionMain()
        {
            return View();
        }

        //
        // GET: /SystemSetting/
        [RequireLogin]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 网站设置主页
        /// </summary>
        /// <returns></returns>
        [RequireLogin]
        public ActionResult WebMain()
        {
            return View();
        }

        /// <summary>
        /// 打开数据字典主界面
        /// </summary>
        /// <returns></returns>
        [RequireLogin]
        public ActionResult DictMain()
        {
            return View();
        }

        [RequireLogin]
        public ActionResult DictManage(string dictKey)
        {
            throw new System.NotImplementedException();
        }

        [RequireLogin]
        public ActionResult GetCitysJsonByParentID(int parentID)
        {
            IList<Citys> citys = BusinessFactory.BasedataBLL.GetCitysByParentID(parentID);
            return Json(citys, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 用于CKEditor 上传图片
        /// </summary>
        /// <param name="upload"></param>
        /// <param name="CKEditorFuncNum"></param>
        /// <param name="CKEditor"></param>
        /// <param name="langCode"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult CKEditorUploadImage(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor, string langCode)
        {
            string path1 = AppDomain.CurrentDomain.BaseDirectory + "uploads\\other";
            string filename = Guid.NewGuid().ToString() + Path.GetExtension(upload.FileName);
            upload.SaveAs(Path.Combine(path1, filename));

            string url = "/uploads/other/" + filename;
            string message = ""; // message to display (optional)

            // since it is an ajax request it requires this string
            string output = @"<html><body><script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\", \"" + message + "\");</script></body></html>";
            return Content(output);
        }
    }
}
